
jQuery(document).ready(function() {



    $('.page-container form .username, .page-container form .password').keyup(function(){
        $(this).parent().find('.error').fadeOut('fast');
    });

});

function loginIn() {
    var username = $("#username").val();
    var password = $("#password").val();
    if(username == ''||username==undefined||username==null) {
        $(this).find('.error').fadeOut('fast', function(){
            $(this).css('top', '27px');
        });
        $(this).find('.error').fadeIn('fast', function(){
            $(this).parent().find('.username').focus();
        });
        return false;
    }
    if(password == ''||password==undefined||password==null) {
        $(this).find('.error').fadeOut('fast', function(){
            $(this).css('top', '96px');
        });
        $(this).find('.error').fadeIn('fast', function(){
            $(this).parent().find('.password').focus();
        });
        return false;
    }
    var url='/idc-resource/login/in',
        data={
            userId:username,
            loginPwd:password,
            deviceId:"web login",
        };
    $.ajax({
        url:url,
        data:JSON.stringify(data),
        contentType: "application/json; charset=utf-8",
        dataType:"json",
        type:"POST",
        success:function(result){
            if(result.success) {
                window.location.href="main.html?token="+result.token+"&id="+result.id;
            }else {
                alert(result.errorMsg);
            }
        }
    });
}

function openRegister() {
    window.location.href="register.html";
}
